<template>
    <div>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>房号名称</td>
                    <td><input type="text" v-model="queryinfo.HouseName"/></td>
                </tr>
                <tr>
                    <td>门店名称</td>
                    <td><select v-model="queryinfo.ShopId">
                        <option value="">请选择</option>
                        <option :value="item.Id" v-for="item in data.list" :key="item.Id">{{ item.ShopName }}</option>
                    </select></td>
                </tr>
                <tr>
                    <td>房型</td>
                    <td><select v-model="queryinfo.HouseTyPeId">
                        <option value="">请选择</option>
                        <option :value="item.Id" v-for="item in data.list1" :key="item.Id">{{ item.HouseTypeName }}</option>
                    </select></td>
                </tr>

                <tr>
                    <td>房态</td>
                    <td><select v-model="queryinfo.HouseState">
                        <option value="">请选择</option>
                        <option :value="1">空闲</option>
                        <option :value="2">已入住</option>
                        <option :value="3">已预约</option>
                    </select></td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="button" value="添加" @click="add" class="btn btn-success"/></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref,reactive, onMounted}from 'vue';
import axios from 'axios';
import moment from 'moment';
import {useRouter,useRoute}from 'vue-router'
const router=useRouter();
const route=useRoute();

let queryinfo:any=reactive({
  "HouseName": "",
  "ShopId": '',
  "HouseTyPeId": '',
  "HouseState": '',
})

let queryinfo2:any=reactive({
    pageindex:1,
    pagesize:2,
})

let data:any=reactive({
    list:[],
    list1:[]
})

onMounted(()=>{
    getshoplist();
    getdist();
})


const getdist=()=>{
    axios({
        url:'/api/House/GetHouseList',
        method:'get',
        params:queryinfo2
    })
    .then(res=>{
        console.log(res);
        data.list1=res.data.list;
    })
    .catch(err=>{
        console.log(err);
    })
}


const getshoplist=()=>{
    axios({
        url:'/api/Shop/Getshop',
        method:'get',
        params:queryinfo2
    })
    .then(res=>{
        console.log(res);
        data.list=res.data.c
    })
    .catch(err=>{
        console.log(err);
    })
}



const add=()=>{
    axios({
        url:'/api/House/AddHOusNo',
        method:'post',
        data:queryinfo,
    })
    .then(res=>{
        console.log(res);
        if(res.data==-1){
            alert('房号名称重复');
            return;
        }
        if(res.data>0){
            alert('添加成功');
            router.push('/nolist');
        }
        else{
            alert('添加失败');
        }
    })
    .catch(err=>{
        console.log(err);
    })
}
</script>

<style scoped>

</style>